home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / annotateNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.4 KB  |  128 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-2001 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. // ==========================================================================
  34. // All rights  reserved.  These coded  instructions,  statements and computer
  35. // programs contain unpublished information  proprietary to  Alias|Wavefront,
  36. // a  division  of  Silicon  Graphics  Limited,  which  is  protected by  the
  37. // Canadian  and  US federal copyright law and  may not be disclosed to third
  38. // parties or  copied  or  duplicated,  in  whole  or in part,  without prior
  39. // written consent of Alias|Wavefront, a division of Silicon Graphics Limited
  40. // ==========================================================================
  41. //
  42. // Creation Date:      October 2001
  43. //
  44. // Written by:    cpam
  45. //
  46. //  Procedure Name:
  47. //      annotateNode
  48. //
  49. //  Description:
  50. //        Brings up a prompt dialog to ask the user for an annotation
  51. //        to add to the selected node.
  52. //
  53. //  Input Arguments:
  54. //        None.
  55. //
  56. //  Return Value:
  57. //      None.
  58.  
  59. proc createAnnotation(string $annotation)
  60. {
  61.     //get the object to annotate
  62.     string $object[] = `ls -sl`;
  63.     
  64.     //make sure it's a valid transform node
  65.     string $checkIfTransform[] = `ls -sl -typ transform $object[0]`;
  66.     if (1 == size($checkIfTransform)) {
  67.  
  68.         //    carry on if it is and calculate the offset for the annotation
  69.         //    based on the object's bounding box
  70.         float $bbox[] = `xform -q -ws -bb $object[0]`;
  71.         $pos[0] = abs($bbox[3] - $bbox[0]);
  72.         $pos[1] = abs($bbox[4] - $bbox[1]);
  73.         $pos[2] = abs($bbox[5] - $bbox[2]);
  74.  
  75.         //    create a locator for easier manipulation
  76.         $locator = `spaceLocator -n "annotationLocator#" `;
  77.         xform -ws -t ($bbox[0]+($pos[0]/2)) 
  78.             ($bbox[1]+($pos[1]/2))
  79.             ($bbox[2]+($pos[2]/2));
  80.         parent $locator $object[0];
  81.  
  82.         //    sort the sides of the bounding box from lowest to highest so 
  83.         //    that the annotation has a more predictable and consistent offset
  84.         $pos = `sort $pos`;
  85.         
  86.         //    add annotation
  87.         select -r $locator;
  88.         $annotationNode = `annotate -tx $annotation 
  89.             -p ($bbox[0]+($pos[2])) 
  90.             ($bbox[1]+($pos[2])) 
  91.             ($bbox[2]+($pos[2]))`;
  92.  
  93.         //    get parent transform of annotation
  94.         string $transform[] = `listRelatives -parent $annotationNode`;
  95.  
  96.         //    parent annotation to locator
  97.         parent $transform[0] $locator;
  98.         select -r $annotationNode;
  99.     } else {
  100.         error "Invalid object selected; only transform nodes may be annotated.";
  101.     }
  102. }
  103.  
  104.  
  105. global proc annotateNode(){
  106.  
  107.     string $result = `promptDialog
  108.         -title "Annotate Node"
  109.         -message "Enter Annotation: "
  110.         -text "Annotation"
  111.         -button "OK"
  112.         -button "Cancel"
  113.         -defaultButton "OK"
  114.         -cancelButton "Cancel"
  115.         -dismissString "Cancel"`;
  116.  
  117.     // If the result was "OK", then proceed
  118.     //
  119.     if ( $result == "OK" ) {
  120.  
  121.         // Get the annotation the user entered
  122.         //
  123.         string $annotation = `promptDialog -q`;
  124.         createAnnotation $annotation;
  125.     }
  126.  
  127. }
  128.